# Maintainer: fauxpark <fauxpark@gmail.com>

_realname=libb64
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.2.1
pkgrel=1
pkgdesc="Base64 Encoding/Decoding Routines (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='http://libb64.sourceforge.net/'
license=('custom:Public Domain')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.zip"
        "https://sources.debian.net/data/main/libb/libb64/1.2-3/debian/patches/bufsiz-as-buffer-size.diff")
sha256sums=('20106f0ba95cfd9c35a13c71206643e3fb3e46512df3e2efb2fdbf87116314b2'
            '0a8a978e94a924b4f62795de251aa1a5ceb53a1024ea60193d7f3e5a5794fa20')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 -i "${srcdir}/bufsiz-as-buffer-size.diff"
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}/src"

  export CFLAGS="${CFLAGS} -fPIC"
  make

  export CFLAGS="${CFLAGS} -shared"
  export LDFLAGS="${LDFLAGS} -Wl,--out-implib,libb64.dll.a"
  ${CC} ${LDFLAGS} ${CFLAGS} *.o -o libb64.dll
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  install -Dm644 src/libb64.dll -t "${pkgdir}${MINGW_PREFIX}/bin"
  install -Dm644 src/libb64.a -t "${pkgdir}${MINGW_PREFIX}/lib"
  install -Dm644 src/libb64.dll.a -t "${pkgdir}${MINGW_PREFIX}/lib"
  cp -r include "${pkgdir}${MINGW_PREFIX}"

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
